﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.ComponentModel;

namespace PatientInformationExtract.Components
{
    public class WindowViewModelBase : INotifyPropertyChanged
    {
        protected Window _window;
        protected WindowViewModelBase _parent;
        public WindowViewModelBase Parent { get { return this._parent; } }
        private bool _isClosed = false;

        protected virtual void WindowInitialize()
        {
            this._isClosed = false;
        }

        protected void BindIsClosed()
        {
            this._window.Closed += new EventHandler(window_Closed);
        }

        private void window_Closed(object sender, EventArgs e)
        {
            this._isClosed = true;
        }

        public virtual void Show()
        {
            if (this._window != null)
            {
                if (this._isClosed)
                {
                    WindowInitialize();
                }
                this._window.Show();
            }
        }

        public virtual bool? ShowDialog()
        {
            if (this._window != null)
            {
                if (this._isClosed)
                {
                    WindowInitialize();
                }
                return this._window.ShowDialog();
            }
            return false;
        }

        public virtual void Close()
        {
            if (this._window != null)
            {
                if (!this._isClosed)
                {
                    this._window.Close();
                }            
            }
        }

        protected void MultiTypeValueChange(MultiTypeValue multiTypeValue, MultiTypeValue.Command command, string propertyName)
        {
            multiTypeValue.SetValue(command);
            NotifyPropertyChanged(propertyName);
        }

        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;

        public void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion
    }
}
